package com.burgess.net.persitent;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.kahadb.KahaDBStore;

import java.io.File;

/**
 * 使用KaHaDB进行存储
 * 创建人    BurgessLee
 * 创建时间   2020/5/22
 * 描述
 */
public class KaHaDBDemo {

    public static void main(String[] args) throws Exception {

        /**
         * 使用内存持久化示例
         */
        BrokerService brokerService = new BrokerService();
        brokerService.setPersistent(false);
        brokerService.addConnector("tcp://localhost:61616");
        brokerService.start();


    }

    BrokerService createEmbeddedBroker() throws Exception {
        BrokerService brokerService = new BrokerService();
        File file = new File("target/amq-in-action/kahadb");
        KahaDBStore kahaDBStore = new KahaDBStore();
        kahaDBStore.setDirectory(file);

        kahaDBStore.setJournalMaxFileLength(1024 * 1000);
        kahaDBStore.setIndexWriteBatchSize(100);
        kahaDBStore.setEnableIndexWriteAsync(true);
        brokerService.addConnector("tcp://localhost:61616");
        brokerService.start();

        return brokerService;
    }
}
